package com.aikon.wht.paoshan.alg;

import java.util.Stack;

/**
 * @author WANGHAITAO273
 */
public class PaoshanOfKuoHao {

    public static void main(String[] args) {
        String s = "{[]}";

        Stack<String> stack = new Stack();
        for (int i = 0; i < s.length(); i++) {
            String c = s.substring(i, i + 1);
            System.out.println(c);
            if (isLeft(c)) {
                stack.push(c);
            } else {
                String t = stack.peek();
                if (isPair(c, t)) {
                    stack.pop();
                }
            }
        }
        System.out.println(stack.size());
    }

    private static boolean isPair(String c, String t) {
        return "{".equals(t) && "}".equals(c) || "[".equals(t) && "]".equals(c) || "(".equals(t) && ")"
                .equals(c);
    }

    private static boolean isLeft(String c) {
        return "{".equals(c) || "[".equals(c) || "(".equals(c);
    }


}